﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Libs.Content;
using System.Web.UI.HtmlControls;

public partial class Pages_News_Detail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int cateID = 0, newsID = 0;
        if (!NewsUtils.CheckUrl(ref cateID, ref newsID))
        {
            Response.Redirect(Constant.HOME_PATH);
        }
        NewsCategories _Cate = new NewsCategories();
        _Cate = _Cate.Get(cateID);
        if (_Cate.CateID == 0)
        {
            Response.Redirect(Constant.HOME_PATH);
        }
        News _News = new News();
        _News = _News.Get(newsID);
        if (_News.NewsID == 0 || _News.Status != 3)
        {
            Response.Redirect(Constant.HOME_PATH);
        }

        //// Kiểm tra nếu là tin ảnh
        //if (cateID == 52)
        //{
        //    Response.Redirect("/slide.html?nid=" + newsID.ToString());
        //}

        //lblTime.Text = _News.PublishedTime.ToString("HH'h'mm '|' dd/MM/yyyy");
        lblTitle.Text = _News.Title;
        Title = _News.Title + " - " + Constant.SiteTitle;
        lblContent.Text = _News.Content;
        //lblHits.Text = _News.Hits.ToString();

        //hlCate.Text = _Cate.Name;
        //hlCate.NavigateUrl = NewsUtils.CateLink(cateID.ToString(), _Cate.Url, "0");

        //_News.AddHits();
        NewsWeb _NewsWeb = new NewsWeb();
        List<NewsWeb> lstNewWeb = _NewsWeb.GetList(_Cate.CateID, _News.NewsID, 10);
        if (lstNewWeb.Count > 0)
        {
            pnOtherNews.Visible = true;
            rptNewList.DataSource = lstNewWeb;
            rptNewList.DataBind();
        }

        //NewsForum _Forum = new NewsForum();
        //rptCommentList.DataSource = _Forum.GetList(newsID, 2);
        //rptCommentList.DataBind();

        //// Tag
        //ltrTags.Text = Tags(_News.Tags);

        // Thêm thẻ meta
        HtmlMeta _des = new System.Web.UI.HtmlControls.HtmlMeta();
        _des.Name = "description";
        _des.Content = _News.Lead;
        Page.Header.Controls.Add(_des);

        HtmlMeta _descript = new System.Web.UI.HtmlControls.HtmlMeta();
        _descript.Name = "og:description";
        _descript.Content = _News.Lead;
        Page.Header.Controls.Add(_descript);

        HtmlMeta _img = new System.Web.UI.HtmlControls.HtmlMeta();
        _img.Name = "og:image";
        _img.Content = AppUtils.ImageUrl(_News.ImageUrl, "200", "200");
        Page.Header.Controls.Add(_img);
    }
}